package com.chenju.invokechainservice.component;

import com.chenju.invokechainservice.common.exceptions.FunnyValidationException;
import com.chenju.invokechainservice.service.impl.FunnyTestServiceImplement;
import com.chenju.invokechainservice.utils.FunnyStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class BuildComponent {

    @Value("${target.buildtool}")
    private String buildTool;

    private final static Logger logger = LoggerFactory.getLogger(FunnyTestServiceImplement.class);

    public String getBuildTool() {
        if (buildTool == null || "maven".equals(buildTool.toLowerCase())){
            return "maven";
        } else if ("gradle".equals(buildTool.toLowerCase())){
            return "gradle";
        }
        throw  new FunnyValidationException(String.format("不支持的编译工具: %s", buildTool.toLowerCase()));
    }

    public String getBuildFileName() {
        if ("maven".equals(getBuildTool())){
            return "pom.xml";
        } else {
            return "settings.gradle";
        }
    }

    public String getClassesDir(){
        if ("gradle".equals(getBuildTool())){
            return "build";
        } else {
            return "target";
        }
    }
}
